//
//  ZPPayOrderViewController.m
//  ZPIOSEducation
//
//  Created by mini1 on 2016/12/7.
//  Copyright © 2016年 mini1. All rights reserved.
//

#import "ZPPayOrderViewController.h"
#import "ZPOrderPayTabViewCell.h"
#import "ZPMoneyPayTabViewCell.h"
#import "ZPOrderGeneratedCell.h"
#import "ZPShareView.h"


static NSString * const reuseIdentifier_money = @"ZPMoneyPayTabViewCell";
static NSString * const reuseIdentifier_order = @"ZPOrderPayTabViewCell";
static NSString * const reuseIdentifier_generated = @"ZPOrderGeneratedCell";
@interface ZPPayOrderViewController () <UITableViewDelegate,UITableViewDataSource>
{
    NSArray *payMethodTitles;
    NSArray *payMethodImages;
}
@property (weak, nonatomic) IBOutlet UITableView *payOrderTableView;
@property (strong, nonatomic) ZPMoneyPayTabViewCell *moneyCell;
@property (strong, nonatomic) ZPOrderPayTabViewCell *orderCell;
@property (strong, nonatomic) ZPOrderGeneratedCell *generatedCell;
@end

@implementation ZPPayOrderViewController
- (ZPMoneyPayTabViewCell *)moneyCell
{
    if (_moneyCell == nil) {
        _moneyCell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([ZPMoneyPayTabViewCell class]) owner:self options:nil] lastObject];
    }
    return _moneyCell;
}
- (ZPOrderPayTabViewCell *)orderCell
{
    if (_orderCell == nil) {
        _orderCell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([ZPOrderPayTabViewCell class]) owner:self options:nil] lastObject];
    }
    return _orderCell;
}

- (ZPOrderGeneratedCell *)generatedCell
{
    if (_generatedCell == nil) {
        _generatedCell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([ZPOrderGeneratedCell class]) owner:self options:nil] lastObject];
    }
    return _generatedCell;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.payOrderTableView.delegate   = self;
    self.payOrderTableView.dataSource = self;
    payMethodTitles = @[@"支付方式",@"微信支付",@"银联支付"];
    payMethodImages = @[@"zhifubao",@"weixin",@"yinlian"];
}


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.title = @"订单支付";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"zhenpin_back"] style:UIBarButtonItemStylePlain target:self action:@selector(clickBackButtonItem)];
}
- (void)clickBackButtonItem
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - <UITableViewDataSource>
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 2;
    } else if (section == 1) {
        return [payMethodTitles count];
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger section = [indexPath section];
    NSInteger row     = [indexPath row];
    if (section == 0)
    {
        if (row == 0)
        {
            self.generatedCell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier_generated];
            return self.generatedCell;
        }
        else
        {
            self.moneyCell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier_money];
            self.moneyCell.selectionStyle = UITableViewCellAccessoryNone;
            //      self.moneyCell.much.text = @"传入支付钱数";
            return self.moneyCell;
        }
        
    }
    else if (section == 1)
    {
        self.orderCell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier_order];
        self.orderCell.selectionStyle = UITableViewCellAccessoryNone;
        self.orderCell.thirdPartyImgView.image = Z_IMAGE(payMethodImages[row]);
        self.orderCell.thirdPartyName.text = payMethodTitles[row];
        return self.orderCell;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0.01;
    } else if (section == 1) {
        return 40.;
    } else return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return 160.;
        }
        return 60;
    } return 50;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] init];
    if (section == 1) {
        UILabel *label = [[UILabel alloc] init];
        [[ZPShareView sharedSingleView] setupLabel:label masksToBounds:NO cornerRadius:0 backgroundColor:UIColorFromRGB(0xEEEEEE) text:@"请选择支付方式:" textColor:UIColorFromRGB(0X999999) font:14. textAlignment:NSTextAlignmentLeft];
        [view addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(view.mas_leading).with.offset(15);
            make.centerY.equalTo(view.mas_centerY);
        }];
    }
    return view;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
